<?php

class Category extends CI_Model{
	
	public $id;
	public $name;
	public $picture = null;
	
	public function getCategoryById($id){
		
		sanitizeID($id);
		
		$row = get_instance()->db->query("SELECT name, picture, id FROM category WHERE id=?", array($id))->row();
		
		return $this->mapArrayToCategory($row);

	}

	public function getAllCategories(){
		$result = get_instance()->db->query("SELECT * FROM category")->result();
		$returnArray =null;
		foreach($result as $row){
			$returnArray[] = $this->mapArrayToCategory($row);
		}
		return $returnArray;
	}

	public function mapArrayToCategory($row){
		$result = new Category();
		foreach($row as $key=>$value){
			$result->$key=$value; 
		}

		return $result;
	}

}